//
//  PictureCollectionViewCell.swift
//  CJPWB
//
//  Created by 陈锦彭 on 16/3/22.
//  Copyright © 2016年 chenjinpeng. All rights reserved.
//

import UIKit
//协议
@objc
protocol PictureCollectionViewCellDelegate : NSObjectProtocol {
   optional func pictureCollectionViewCellAddPictureBtnClick(cell : PictureCollectionViewCell)
    optional func pictureCollectionViewCellRemovePictureBtnClick(cell : PictureCollectionViewCell)

}

class PictureCollectionViewCell: UICollectionViewCell {
    // MARK: - 属性
    @IBOutlet weak var imageBtn: UIButton!
    @IBOutlet weak var removeBtn: UIButton!
    
    ///图片数据
    var image : UIImage? {
        didSet{
            if image != nil {
              imageBtn.setBackgroundImage(image, forState: .Normal)
               imageBtn.userInteractionEnabled = false
              removeBtn.hidden = false
            }else {
            imageBtn.setBackgroundImage(UIImage(named: "compose_pic_add"), forState: .Normal)
            imageBtn.userInteractionEnabled = true
            removeBtn.hidden = true
            }
            
        }
    }
    ///代理
    var delegate : PictureCollectionViewCellDelegate?
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
     //监听添加图片按钮的点击事件
    @IBAction func addPictureBtnClick(sender: AnyObject) {
        if delegate?.respondsToSelector("pictureCollectionViewCellAddPictureBtnClick:") != nil {
        delegate?.pictureCollectionViewCellAddPictureBtnClick!(self)
        }
    }
    
    @IBAction func removePictureBtnClick(sender: AnyObject) {
       if delegate?.respondsToSelector("pictureCollectionViewCellRemovePictureBtnClick:") != nil{
        delegate?.pictureCollectionViewCellRemovePictureBtnClick!(self)
        
        }
    }
   
}


